from rest_framework import serializers

from apps.goods.models import SPU, GoodsCategory, Brand


class SPUGoodsSerializer(serializers.ModelSerializer):
    '''
        spu序列化器
    '''
    # 返回品牌名称
    brand = serializers.StringRelatedField()
    # 返回品牌id
    brand_id = serializers.IntegerField(read_only=True)
    # 返回一级分类id
    category1_id = serializers.IntegerField(read_only=True)
    # 返回二级分类id
    category2_id = serializers.IntegerField(read_only=True)
    # 返回三级分类id
    category3_id = serializers.IntegerField(read_only=True)

    class Meta:
        model = SPU
        fields = '__all__'


class BrandSerializer(serializers.ModelSerializer):
    '''
        简单品牌序列化器
    '''
    class Meta:
        model = Brand
        fields = '__all__'


class SKUGoodsCategorySerializer(serializers.ModelSerializer):
    '''
        获取三级分类数据
    '''
    class Meta:
        model = GoodsCategory
        # exclude = ('parent',)
        fields = '__all__'